package com.idp.web.test.service.impl;

import com.idp.web.test.service.WarehouseService;
import com.idp.web.test.dao.LogisticsHasWarehouseDao;
import com.idp.web.test.dao.OrdertDao;
import com.idp.web.test.dao.OutDao;
import com.idp.web.test.dao.PutDao;
import com.idp.web.test.dao.WarehouseDao;
import com.idp.web.test.entity.Warehouse;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.idp.common.persistence.Page;

/**
 * 
 * 123123service实现类
 * 
 * <pre>
 * 	历史记录：
 * 	2017-06-02 Amber
 * 	新建文件
 * </pre>
 * 
 * @author
 * 
 * 		<pre>
 * SD
 * 	Amber
 * PG
 *	Amber
 * UT
 *
 * MA
 *         </pre>
 * 
 * @version $Rev$
 *
 *          <p/>
 *          $Id$
 *
 */
@Service("warehouseService")
public class WarehouseServiceImpl implements WarehouseService {

	@Resource
	private WarehouseDao warehouseDao;
	@Resource
	private LogisticsHasWarehouseDao logisticsHasWarehouseDao;
	@Resource
	private OrdertDao ordertDao;
	@Resource
	private PutDao putDao;
	@Resource
	private OutDao outDao;

	@Override
	public Page<Warehouse> findByPage(Warehouse warehouse, Page<Warehouse> page) {

		page.setResult(warehouseDao.find(warehouse, page));

		return page;
	}

	@Override
	public List<Warehouse> findBySearch(Warehouse warehouse) {

		return warehouseDao.find(warehouse);
	}

	@Override
	public Warehouse getById(Integer id) {

		return warehouseDao.getById(id);
	}

	@Override
	public int add(Warehouse warehouse) {
		warehouseDao.add(warehouse);
		return warehouse.getId();
	}

	@Override
	public void update(Warehouse warehouse) {

		warehouseDao.update(warehouse);
	}

	@Override
	public void delete(Integer id) {
		warehouseDao.delete(id);
	}

	@Override
	public boolean checkEmpty(Integer id) {
		if (logisticsHasWarehouseDao.findByWareHouseId(id).size() != 0 || ordertDao.findByWareHouseId(id).size() != 0
				|| putDao.findByWareHouseId(id).size() != 0 || outDao.findByWareHouseId(id).size() != 0) {
			return false;
		} else {
			return true;
		}
	}

}